<template>
	<view>
	
		<u-sticky offset-top="1">
			<u-tabs :lineWidth="25" :list="orderlist" @click="selectStatues">
				<view slot="right" style="padding-left: 12px;" >
					<u-icon name="list" size="21" bold></u-icon>
				</view>
			</u-tabs>

		</u-sticky>


		<view class="search">
			<u-search class="left" placeholder="请输入订单号" @change="selectparams" :bgColor="searchstyle"
				:borderColor="borderstyle" :showAction="false" v-model="keyword"></u-search>
			<view class="backtop">
				<u-button type="primary" @click="topback(status)" class="custom-style" :plain="true" size="mini"
					text="刷新"></u-button>

			</view>

		</view>

	
		<view v-if="empty == 'isempty'" class="list">
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png">

			</u-empty>
		</view>

	




	<view class="content">
		<u-cell-group v-if="empty == 'notempty'">

<u-swipe-action :autoClose="true">

	<u-list  height="650"  :preLoadScreen="page * 4" @scrolltolower="scrolltolower">

		<u-list-item v-for="item in list" :key="item.id">

			<u-swipe-action-item @click="action"
				:disabled="(this.auth.id == '1' || item.status !== '6') ? true : false" :options="options"
				:name="item.id">


			<!-- 租车退款 -->
				<u-cell  @click="info(item.id)" v-if="item.soure == 'hire'"   :label="'门店 : ' +
					item.store.name +
				
					'  车牌号 : ' +
					item.carnumberplate +  

					'   订单类型 : ' + item.soure_text +
	
					'  下单时间 :' +
					item.createtime_text
					" :key="item.id" center>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">客户昵称: {{ item.business.nickname }}</text>
							
						
					<span class="tag">
						<u-tag v-if="item.status == '6'" :text="item.status_text" plain="true" size="mini"
							type="error" />
					</span>
						
				<span class="tag">
					<u-tag v-if="item.status == '7'" :text="item.status_text" plain="true" size="mini"
							type="success" />
				</span>
						
				<span class="tag">
						
					<u-tag v-if="item.status == '8'" :text="item.status_text" plain="true" size="mini"
							type="warning" />
				</span>
						

					</view>
				</u-cell>
				<!-- 服务退款 -->
				<u-cell  v-else @click="info(item.id)" v-if="item.soure == 'clear'"   :label="'门店 : ' +
					item.store.name +
				
					'  车牌号 : ' +
					item.carpark.carnumberplate +

					'订单类型 : ' + item.soure_text +
	
					'  下单时间 :' +
					item.createtime_text
					" :key="item.id" center>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">客户昵称: {{ item.business.nickname }}</text>
							
						
					<span class="tag">
						<u-tag v-if="item.status == '6'" :text="item.status_text" plain="true" size="mini"
							type="error" />
					</span>
						
				<span class="tag">
					<u-tag v-if="item.status == '7'" :text="item.status_text" plain="true" size="mini"
							type="success" />
				</span>
						
				<span class="tag">
						
					<u-tag v-if="item.status == '8'" :text="item.status_text" plain="true" size="mini"
							type="warning" />
				</span>
						

					</view>
				</u-cell>

			</u-swipe-action-item>
		</u-list-item>

		<u-loadmore :status="flag" :loading-text="loadingText" :loadmore-text="loadmoreText"
			:nomore-text="nomoreText" />

	</u-list>
</u-swipe-action>

</u-cell-group>
	</view>

		<!-- 消息提醒 -->
		<u-toast ref="notice"></u-toast>

		<u-modal :show="show" @confirm="rejectOrder" @cancel="cancel" showCancelButton title="是否确认拒绝退款" ref="uModal"
			:asyncClose="true"></u-modal>
	</view>
</template>

<script>
export default {
	onLoad() {
		this.auth = this.$u.auth.check()
		this.ShdataList()
		this.statuList()


	}, 
	
	created() {
		this.timer = setInterval(() => {
		
			this.$u.count.check()
	}, 15000);

},
beforeDestroy() {
	clearInterval(this.timer)
},
	data() {
		return {
			count:{},
			qx: "",
			flag: 'loading',
			keyword:"",
			loadingText: '努力加载中',
			loadmoreText: '下拉加载更多',
			nomoreText: '没有更多数据了',
			orderlist: [],
			status: 1,
			searchstyle: "#ffffff",
			borderstyle: "#eee",
			show: false,
			auth: {},
			list: [],
			page: 1,
			orderid: 0,
			empty: "",
			total1: 0,
			total2: 0,
			btnStyle: {
				width: "52px",
				margin: "5% 80%",
				height: "25px",
			},
			options: [

			
				{
					ststus: 8,
					text: "拒绝",
					style: {
						backgroundColor: "#f56c6c",
					},
				},
			],
		};
	},
	methods: {

		selectparams(e)
		{
			this.list = []
			this.keyword = e
			this.ShdataList()
		},
		
		async topback(e) {
			this.list = []
			this.ShdataList({ status: e, page: 1 })
		},
		
		async selectStatues(e) {
		
	
			this.list = []
			// 请求数据就把数据加载的打开
			this.qx = ""
			this.status = e.status

			

			let data = {
				adminid: this.auth.id,
				status: e.status,
				stoid: this.auth.stoid,
				page: 1
			}


			let result = await this.$u.api.order.Shindex(data)
		
			if (result.code) {

				if (Array.isArray(result.data.list) && result.data.list.length > 0) {
					this.empty = "notempty"
					// 有数据返回就把数据加载的关闭
					this.list =  result.data.list

				} else {
						// this.empty = "isempty"


						this.flag = "nomore"
					

				}
			}

		},
		async statuList()
		{

			let data = {
				adminid:this.auth.id,
				stoid:this.auth.stoid
			}
			let result = await this.$u.api.order.ShouhouStatus(data)
			if(result.code)
			{
				this.orderlist = result.data
			}
		},
		action(item) {

			
			if (item.index == 0) {
				this.show = true
				this.orderid =item.name[0]


			}

		},
		scrolltolower() {
			
			this.ShdataList()



		},
		async rejectOrder() {

			this.show = false;
			let data = {
				status: this.status,
				adminid: this.auth.id,
				orderid: this.orderid
			}

			let result = await this.$u.api.order.reject(data)

			if (result.code) {
				this.$refs.notice.show({
					type: "success",
					message: result.msg,
					duration: 2000,

				})
				setTimeout(() => {
					this.ShdataList()
				}, 350)

				this.$u.route({
					url:"/pagesB/order/shouhou/index"
				})
			} else {
				this.$refs.notice.show({
					type: "error",
					message: result.msg,
					duration: 2000
				})
			}
		},
		cancel() {
			this.show = false;
		},
	

		async ShdataList(e) {
          
		
			if (e) {

				this.page =e.page
				this.status =e.status
			}

			let data = {

				stoid: this.auth.stoid,
				adminid: this.auth.id,
				status: this.status,
				page: this.page,
				keyword:this.keyword

			};



			let result = await this.$u.api.order.Shindex(data);
			
			if (result.code) {
				
				if (Array.isArray(result.data.list) && result.data.list.length > 0) {

					this.empty = "notempty"

					this.list = this.list.concat(result.data.list);
					
					this.page++



				} else {
					this.flag = "nomore"

				}
			}
		},
	
		// 提示音并且待震动
		playSound() {
			uni.vibrateLong()
			const innerAudioContext = uni.createInnerAudioContext() // 创建InnerAudioContext实例
			innerAudioContext.src = '/static/y781.mp3' // 指定音频文件路径
			innerAudioContext.play() // 播放音频文件
		},
		info(e)
		{
			
			this.$u.route("/pagesB/order/shouhou/info",{
				orderid:e

			})
			
			
		}

	},
};
</script>

<style lang="scss">

.content {
	margin-top: 65px;
}
.tag {
	width: 48px;
	right: 10px;
	top: 30px;
	position: absolute;
}
.list-cell {
	display: flex;
	box-sizing: border-box;
	width: 100%;
	padding: 10px 24rpx;
	overflow: hidden;
	color: #323233;
	font-size: 14px;
	line-height: 24px;
	background-color: #fff;
}

.u-tag--mini.data-v-1481d46d {
	width: 38px;
	right: 0;
	top: 3px;
	position: absolute;
}

.u-cell__label {
	width: 241px;
}

.search {
	width: 80%;
	position: fixed;
	top:8.5%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	left: 7%;
	z-index: 999;

}

.backtop {
	width: 20px;
	color: "blue";
	margin-left: 15px;
}

.u-cell__body {
	position: relative;
}

.recordBox {
	height: 100%;
	padding: 0 40rpx;

	.recordItem {
		margin-top: 20rpx;
		background-color: #ffffff;

		.title {
			height: 66rpx;
			padding: 0 20rpx;
			line-height: 66rpx;
			background: #e1e1e1;
			font-size: 32rpx;
			color: #141414;
			text-align: center;
		}

		.contentList {
			display: flex;
			flex-direction: column;
			font-size: 28rpx;
			color: #6d6d6d;

			.contentItem {
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px dashed #c1c1c1;
				height: 66rpx;
				padding: 0 20rpx;
				line-height: 66rpx;
			}
		}

		.showDetail {
			color: #548afb;
			padding: 20rpx 0;
			display: flex;
			align-items: center;
			justify-content: space-around;
		}

	}
	.u-icon__icon.data-v-172979f2 {
	padding-right: 36rpx;
}
}
</style>
